<?php


namespace app\common\validate;


use think\Validate;

class MallUserAddress extends Validate
{
    protected $rule = [
        'name' => 'require|length:1,10',
        'phone' => 'require|checkPhone',
        'country' => 'require|length:1,15',
        'province' => 'require|length:1,15',
        'city' => 'require|length:1,15',
        'address_desc' => 'require|length:1,100',
        'is_default' => 'require|boolean',
    ];

    protected $message = [
        'name.require' => '请输入收件人姓名！',
        'name.max' => '收件人姓名最长10个字！',
        'phone.require' => '收货人手机号码不能为空！',
        'phone.checkPhone' => '手机号码错误！',
        'country.require' => '请选择收货地址！',
        'country.length' => '收货地址错误！',
        'province.require' => '请选择收货地址！',
        'province.length' => '收货地址错误！',
        'city.require' => '请选择收货地址！',
        'city.length' => '收货地址错误！',
        'address_desc.require' => '请选择详细地址！',
        'address_desc.length' => '详细地址最多100个字！',
        'is_default.boolean' => '请求数据异常！',
    ];

    public function checkPhone($value, $rule)
    {
        return preg_match("/^1[3456789]{1}\d{9}$/", $value) ? true : false;
    }
}
